﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WS.EKA.Business.Model;
using WS.EKA.Business.Dal;
using Oracle.DataAccess.Client;
using WS.EKA.Utility;

namespace WS.EKA.Business.Service
{
    public class EventService : AbstractService<TB_EVENT_TEMP>
    {
        IDB db = DBFactory.CreateBODB();

        public override void ImportData(IList<TB_EVENT_TEMP> list)
        {
            foreach (var item in list)
            {
                int id = 0;
                int.TryParse(db.ExecuteScalar("select Tb_Event_Temp_Seq.nextval from sys.dual"), out id);
                item.Id = id;

                SyncApplication(item.App_Code, item.App_Name, item.App_Level);
            }
            base.ImportData(list);
        }
        public override void SyncData()
        {
            db.ExecuteStoredProcedure("USP_SYNC_EVENT");
        }

        public void SyncApplication(string appCode, string appName, string appLevel)
        {

            try
            {
                OracleParameter[] p = new OracleParameter[3];
                p[0] = new OracleParameter("APP_CODE", OracleDbType.Varchar2, appCode, ParameterDirection.Input);
                p[1] = new OracleParameter("APP_NAME", OracleDbType.Varchar2, appName, ParameterDirection.Input);
                p[2] = new OracleParameter("APP_LEVEL", OracleDbType.Varchar2, appLevel, ParameterDirection.Input);
                DBFactory.CreateARDB().ExecuteStoredProcedure("WS_BUSINESSSYSTEMSYNC", p);
            }
            catch (Exception ex)
            {
                Logger.Log("EventService SyncApplication Error.");
                Logger.Error("EventService SyncApplication Error.", ex);
            }
        }
    }
}
